package com.huixiaodian.baselibrary.retrofit;

import android.content.Context;

import com.huixiaodian.baselibrary.common.Constant;
import com.huixiaodian.baselibrary.interceptor.ReceivedCookieInterceptor;

import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class RetrofitClient {

    public static Retrofit getRetrofitClient(Context context){
        OkHttpClient okHttpClient = new OkHttpClient();
        okHttpClient.interceptors().add(new ReceivedCookieInterceptor(context));
        return retrofitBuilder().client(okHttpClient).build();
    }

    public static Retrofit getRetrofitClientSaveCookie(Context context){
        OkHttpClient okHttpClient = new OkHttpClient();
        okHttpClient.interceptors().add(new ReceivedCookieInterceptor(context));
        return retrofitBuilder().client(okHttpClient).build();
    }

    private static Retrofit.Builder retrofitBuilder(){
        return new Retrofit.Builder()
                .addConverterFactory(GsonConverterFactory.create())
                .baseUrl(Constant.host);
    }
}
